<template>
    <div>
        <el-card class="!border-none" shadow="never">
            <div class="mt-4" v-loading="pager.loading">
                <div>
                    <el-table :data="pager.lists" size="large">
                        <el-table-column prop="open_id" label="openid" min-width="100" />
                        <el-table-column label="操作" width="320" fixed="right">
                            <template #default="{ row }">
                                <el-button link type="primary" @click="handleCheck(row, 0)" v-if="row.status == 1">
                                    禁用
                                </el-button>
                                <el-button link type="primary" @click="handleCheck(row, 1)" v-if="row.status == 0">
                                    启用
                                </el-button>
                                <el-button link type="danger" @click="handleDelete(row.id)">
                                    删除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <div class="flex justify-end mt-4">
                    <pagination v-model="pager" @change="getLists" />
                </div>
            </div>
        </el-card>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { usePaging } from '@/hooks/usePaging'
import { openidLists, openidDelete, openidDisable } from '@/api/apis'
import feedback from '@/utils/feedback'

const { pager, getLists } = usePaging({
    fetchFun: openidLists
})


const handleCheck = async (row: any, status: number) => {
    console.log(row)
    await openidDisable({ id: row.id, status: status })
    getLists()
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await openidDelete({ id })
    getLists()
}
getLists()

</script>

<style scoped></style>